package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.BaiStory;
import com.ruoyi.system.service.IBaiStoryService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 奇闻轶事Controller
 * 
 * @author saruri
 * @date 2024-07-21
 */
@RestController
@RequestMapping("/story")
public class BaiStoryController extends BaseController
{
    @Autowired
    private IBaiStoryService baiStoryService;

    /**
     * 获取上一条奇闻轶事
     */

    @GetMapping(value = "/prev/{id}")
    public AjaxResult getPrev(@PathVariable("id") Long id)
    {
        return success(baiStoryService.selectBaiStoryPrevById(id));
    }

    /**
     * 获取上一条奇闻轶事
     */

    @GetMapping(value = "/next/{id}")
    public AjaxResult getNext(@PathVariable("id") Long id)
    {
        return success(baiStoryService.selectBaiStoryNextById(id));
    }




    /**
     * 获取最新奇闻轶事详细信息
     */

    @GetMapping(value = "/new")
    public AjaxResult getInfoNew()
    {
        return success(baiStoryService.selectBaiStoryNew());
    }


    /**
     * 查询奇闻轶事列表
     */

    @GetMapping("/list")
    public TableDataInfo list(BaiStory baiStory)
    {
        startPage();
        List<BaiStory> list = baiStoryService.selectBaiStoryList(baiStory);
        return getDataTable(list);
    }

    /**
     * 导出奇闻轶事列表
     */
    @RequiresPermissions("system:story:export")
    @Log(title = "奇闻轶事", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaiStory baiStory)
    {
        List<BaiStory> list = baiStoryService.selectBaiStoryList(baiStory);
        ExcelUtil<BaiStory> util = new ExcelUtil<BaiStory>(BaiStory.class);
        util.exportExcel(response, list, "奇闻轶事数据");
    }

    /**
     * 获取奇闻轶事详细信息
     */

    @GetMapping(value = "/content/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(baiStoryService.selectBaiStoryById(id));
    }

    @GetMapping(value = "/{id}")
    public AjaxResult getInfo1(@PathVariable("id") Long id)
    {
        return success(baiStoryService.selectBaiStoryById(id));
    }


    /**
     * 新增奇闻轶事
     */
    @RequiresPermissions("system:story:add")
    @Log(title = "奇闻轶事", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaiStory baiStory)
    {
        return toAjax(baiStoryService.insertBaiStory(baiStory));
    }

    /**
     * 修改奇闻轶事
     */
    @RequiresPermissions("system:story:edit")
    @Log(title = "奇闻轶事", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaiStory baiStory)
    {
        return toAjax(baiStoryService.updateBaiStory(baiStory));
    }

    /**
     * 删除奇闻轶事
     */
    @RequiresPermissions("system:story:remove")
    @Log(title = "奇闻轶事", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(baiStoryService.deleteBaiStoryByIds(ids));
    }


//TAG_START:BaiStory_Top_list

// 控制器
@GetMapping("/top")
public TableDataInfo listTop(BaiStory baiStory) {
    startPage();
    List<BaiStory> list = baiStoryService.selectBaiStoryListTop(baiStory);
    return getDataTable(list);
}

//TAG_END:BaiStory_Top_list


}
